using MultiAgentsClient.Service.WorkflowEngine.BaseNodes;
using MultiAgentsShared;

namespace MultiAgentsClient.Service.WorkflowEngine.BuiltInNodes;

public class NodeOutputRequest(string nodeId) : NodeRequestToService(nodeId)
{
    public int chatRoomId = 0;
    public string workflowName = "";
    public string outputContent = "";
}

public class NodeOutputResponse(string nodeId) : NodeResponseFromService(nodeId) { }

[NodeGraphPortDef(1, 0)]
public class OutputNode : ServiceDependentNode<NodeOutputRequest, NodeOutputResponse>
{
    [NodeGraphParam] public string OutputVariable = "";
    private string OutputVariableRuntime => InsertVariable(OutputVariable);
    public OutputNode() : base() { }

    protected override void SendRequestToService()
    {
        NodeOutputRequest outputRequest = new(Id)
        {
            chatRoomId = runtimeContext.ChatRoomIdForSession,
            workflowName = runtimeContext.BehaviorTreeName,
            outputContent = OutputVariableRuntime,
        };

        EventBus.Publish(outputRequest);
    }

    protected override NodeOutcome ServiceResponseHandler(NodeOutputResponse _)
    {
        return new NodeOutcome(NodeOutcomeStatus.Success, 0);
    }
}
